package kr.hkit.androidcomplete02.ch12;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

public class SpinnerEx extends Activity {
	ArrayAdapter<CharSequence> adapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch12_spinner);
		
		Spinner spin = (Spinner) findViewById(R.id.myspinner);
		spin.setPrompt("과일을 고르세요");
		
		adapter = ArrayAdapter.createFromResource(this, R.array.fruits,
				android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		/* adspin.setDropDownViewResource(android.R.layout.simple_spinner_item); */
	
		spin.setAdapter(adapter);
		
		spin.setOnItemSelectedListener(new OnItemSelectedListener() {
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				String text = adapter.getItem(position) + "는 맛있다.";
				Toast.makeText(getBaseContext(), text, Toast.LENGTH_LONG)
						.show();
			}

			public void onNothingSelected(AdapterView<?> parent) {
			}
		});
	}
}